{include file="common/_meta" /}
<title>糖果机列表</title>
</head>
<body class="pos-r">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 矿机管理 <span class="c-gray en">&gt;</span> 矿机项目 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="page-container">
		<form class="Huiform" method="get" action="" >
		<div class="text-c"> 
	<!-- 		状态：
			<span class="select-box inline">
				<select name="status" class="select">
					<option value="0" >生产中</option> 
					<option value="1" style="color:green;">已完成</option>
				</select>
			</span>
			&nbsp;&nbsp;
 			<input type="text" class="input-text" style="width:250px" placeholder="会员姓名、手机号" id="" name="keywords" value="{$Request.get.keywords|default=''}">
			<input type="text" class="input-text" style="display: none;" placeholder="" name="page" value="1">
			<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button> -->
		</div>
		</form>
		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<a class="btn btn-primary radius" onclick="cmAdd()" href="javascript:;">
				<i class="Hui-iconfont"></i>
				添加矿机
			</a>
			<span class="r">共有数据：<strong>{$list->total()}</strong> 条</span> </div>
		<div class="mt-20">
			<table class="table table-border table-bg table-hover table-sort">
				<thead>
					<tr class="text-c">
						<th ><input name="" type="checkbox" value=""></th>
						<th >ID</th>
						<th>矿机名称</th>
						<th>类别</th>
						<th>价格</th>
						<th>总周期（天）</th>
						<th>展期（天）</th>
						<th>期数</th>
						<th>每期收益比</th>
						<th>总收益(元)</th>
						<th>状态</th>
						<th >操作</th>
					</tr>
				</thead>
				<tbody>
					{volist name="list" id="vo"}
					<tr class="text-c va-m">
						<td><input name="" type="checkbox" value=""></td>
						<td>{$i}</td>
						<td>{$vo.type_name}</td>
						<td>{$items[$vo.item_id]}</td>
						<td>{$vo.price}</td>
						<td>{$vo.lifetime}</td>
						<td>{$vo.phased}</td>
						<td>{$vo.num}</td>
						<td><a href="javascript:;" onClick="cmup({$vo.num}, {$vo.type_id})">{$vo.different|implode="%，",###}%</a></td>
						<td>{$vo.candy_num}</td>
						<td class="td-status">
							{if condition="$vo.status eq 1"}
							<span class="label label-success radius">已上架</span>
							{else/}
							<span class="label label-error radius">已下架</span>
							{/if}
						</td>
						<td class="td-manage">
							{if condition="$vo.status eq 1"}
							<a style="text-decoration:none" onClick="us_stop(this,{$vo.type_id})" href="javascript:;" title="下架">
								<i class="Hui-iconfont">&#xe641;</i>
							</a>
							{else/}
							<a style="text-decoration:none" onClick="us_start(this,{$vo.type_id})" href="javascript:;" title="上架">
								<i class="Hui-iconfont">&#xe642;</i>
							</a>
							{/if} &nbsp;&nbsp;
							<a style="text-decoration:none" href="javascript:;" onClick="cmEdit(this, {$vo.type_id})" title="编辑">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
						</td>
					</tr>
					{/volist}
				</tbody>
			</table>
			<div class="pages" style="margin:20px;float: right; ">{$list->render()}</div>
		</div>
	</div>

	<div id="cm_edit" class="modal fade" style="margin: 0 auto;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
		 aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content radius">
					<div class="modal-header">
						<h3 class="modal-title"></h3>
						<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
					</div>
					<div class="modal-body">
						<article class="page-container" style="padding-right: 10%;">
							<form action="" method="post" class="form form-horizontal" id="form-user-add">
								<div class="row cl hidden">
									<label class="form-label col-xs-4 col-sm-3"></label>
									<div class="formControls col-xs-8 col-sm-9">
										<input type="text" name="type_id" id="type_id" class="input-text" placeholder="" autocomplete="off">
									</div>
								</div>
								<div class="row cl">
									<label class="form-label col-xs-4 col-sm-3">矿机名称：</label>
									<div class="formControls col-xs-8 col-sm-9">
										<input type="text" name="type_name" id="type_name" class="input-text" autocomplete="off">
									</div>
								</div>
								<div class="row cl">
									<label class="form-label col-xs-4 col-sm-3">所属分类：</label>
									<div class="formControls col-xs-8 col-sm-9">
										<select class="input-text" name="item_id" autocomplete="off">
												{volist name="items" id="vo"}
												<option value="{$key}">{$vo}</option>
												{/volist}
										</select>
									</div>
								</div>
								<div class="row cl">
									<label class="form-label col-xs-4 col-sm-3">矿机价格(￥)：</label>
									<div class="formControls col-xs-8 col-sm-9">
										<input type="text" name="price" id="price" class="input-text" autocomplete="off">
									</div>
								</div>
								<div class="row cl">
									<label class="form-label col-xs-4 col-sm-3">总收益(￥)：</label>
									<div class="formControls col-xs-8 col-sm-9">
										<input type="text" name="candy_num" id="candy_num" class="input-text" autocomplete="off">
									</div>
								</div>
								<div class="row cl">
									<label class="form-label col-xs-4 col-sm-3">总周期(天)：</label>
									<div class="formControls col-xs-8 col-sm-9">
										<input type="text" name="lifetime" id="lifetime" class="input-text" autocomplete="off">
									</div>
								</div>
								<div class="row cl">
									<label class="form-label col-xs-4 col-sm-3">展期(天)：</label>
									<div class="formControls col-xs-8 col-sm-9">
										<input type="text" name="phased" id="phased" class="input-text" autocomplete="off">
									</div>
								</div>
								
								<div class="row cl">
									<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
										<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
									</div>
								</div>
							</form>
						</article>
					</div>
				</div>
			</div>
	</div>
	<!--  -->
	<div id="cm_update" class="modal fade" style="margin: 0 auto;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
		 aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content radius">
					<div class="modal-header">
						<h3 class="modal-title"></h3>
						<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
					</div>
					<div class="modal-body">
						<article class="page-container" style="padding-right: 10%;">
							<form action="" method="post" class="form form-horizontal" id="form-user-update">
							<div id="to_update"></div>
							<div class='row cl'>
								<div class='col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3'>
								<input class='btn btn-primary radius' type='submit' value='&nbsp;&nbsp;提交&nbsp;&nbsp;'>
								</div>
							</div>
							</form>
						</article>
					</div>
				</div>
			</div>
	</div>

</div>
{include file="common/_footer" /}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
$('select[name="status"]').val('{$Request.get.status|default=0}');
$('select[name="type_id"]').val('{$Request.get.type|default=0}');

function us_stop(obj, id) {
	layer.confirm('确认要下架吗？', function (index) {
		$.ajax({
			type: 'POST',
			url: "{:url('cmType')}?acc=status",
			data: { 'id': id},
			dataType: 'json',
			success: function (data) {
				if (data.code) {
					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="us_start(this,' + id + ')" href="javascript:;" title="上架"><i class="Hui-iconfont">&#xe642;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
					$(obj).remove();
				}
				layer.msg(data.msg, { icon: 6, time: 1000 });
			},
			error: function (data) {
				console.log(data.msg);
			},
		});
	});
}

function us_start(obj, id) {
	layer.confirm('确认要上架吗？', function (index) {
		$.ajax({
			type: 'POST',
			url: "{:url('cmType')}?acc=status",
			data: { 'id': id },
			dataType: 'json',
			success: function (data) {
				if (data.code) {
					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="us_stop(this,' + id + ')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe641;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已上架</span>');
					$(obj).remove();
				}
				layer.msg(data.msg, { icon: 6, time: 1000 });
			},
			error: function (data) {
				console.log(data.msg);
			},
		});
	});
}

function cmAdd()
{
	$("#cm_edit input[type!=submit]").val('');
    $("#cm_edit").modal("show");
}

function cmup (num, id)
{
	$.get("{:url('cmType')}", {type_id:id}, function(data){
		$("#form-user-update input[type!=submit]").val('');
		$("#to_update").empty();
		var inp ="<div class='row cl hidden'>"
				+"<label class='form-label col-xs-4 col-sm-3'></label>"
				+"<div class='formControls col-xs-8 col-sm-9'>"
					+"<input type='text' name='type_id' id='type_id' class='input-text' placeholder='' value = '"+id+"' autocomplete='off'>"
				+"</div>"
			+"</div>";
		for (var i=1; i <= num-1; i++) {
			inp += "<div class='row cl'>"
				+"<label class='form-label col-xs-4 col-sm-3'>第"+i+"期收益比：</label>"
				+"<div class='formControls col-xs-8 col-sm-9'>"
					+"<input type='text' name='cm_diff"+(i-1)+"' id='type_name' class='input-text' value = '"+data.diff[i-1]+"' autocomplete='off'>"
				+"</div>"
			+"</div>";
		}
		$("#to_update").prepend(inp);
    	$("#cm_update").modal("show");
    });
}

function cmEdit(obj, id)
{
	$.get("{:url('cmType')}", {type_id:id}, function(data){
		if (data) {
			$('#type_id').val(data.type_id);
			$('#type_name').val(data.type_name);
			$('#price').val(data.price);
			$('#price').val(data.price);
			$('#candy_num').val(data.candy_num);
			$('#phased').val(data.phased);
			$('#lifetime').val(data.lifetime);
		}
	});
	$("#cm_edit").modal("show");
}

$("#form-user-add").find('input:submit').click(function(){
	$.post("{:url('cmType')}?acc=edit", $('#form-user-add').serialize(), function(data){
		layer.msg(data.msg);
		if (data.code) {
			setTimeout(function(){
				history.go(0);
			}, 500);
		}
	});

	return false;
});

$("#form-user-update").find('input:submit').click(function(){
	$.post("{:url('cmType')}?acc=diff", $('#form-user-update').serialize(), function(data){
		console.log(data);
		layer.msg(data.msg);
		if (data.code) {
			setTimeout(function(){
				history.go(0);
			}, 500);
		}
	});

	return false;
});

$(function(){
  $('.table-sort').dataTable({
    "aaSorting": [[ 0, "desc" ]],//默认第几个排序
    "bStateSave": true,//状态保存
    "aoColumnDefs": [
      //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
      {"orderable":false,"aTargets":[0,2,4]}// 制定列不参与排序
    ]
  });
});
</script>
</body>
</html>